package com.sandau.basic.service.impl;

import com.sandau.basic.domain.User;
import com.sandau.basic.global.GlobalEnum;
import com.sandau.basic.mapper.UserMapper;
import com.sandau.basic.service.UserService;
import com.sandau.basic.utils.Converter;
import com.sandau.basic.vo.UserVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class UserServiceimpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public GlobalEnum.ErrorCode addUser(UserVo userVo) {
        GlobalEnum.ErrorCode errorCode = GlobalEnum.ErrorCode.USER_ADD_FAIL;
        User user = new User();
        user.setUsername(userVo.getUsername());
        user.setPassword(userVo.getPassword());
        user.setEmail(userVo.getEmail());
        user.setMobile(userVo.getMobile());
        user.setBirthday(Converter.lovalDateToDate(userVo.getBirthday()));
        user.setEnName(userVo.getEnName());
        user.setIsActive(true);
        user.setProfileUrl(userVo.getProfileUrl());
        user.setCreateperson(1);
        user.setUpdateperson(1);
        user.setCreatetime(Converter.localDateTimeToDate(LocalDateTime.now()));
        user.setUpdatetime(Converter.localDateTimeToDate(LocalDateTime.now()));
        userMapper.insert(user);
        return errorCode;


    }
}
